<template>
    <div>
      <x-header :left-options="{backText:'', preventGoBack: 'true'}"
                @on-click-back="$router.go(-2)">
        附件详情
      </x-header>
      <div v-if="!openFile" class="file">
        <img src="../../svg/word.svg" alt="" class="file-icon">
        <p class="file-name">{{fileName}} </p>
        <p class="file-size">{{fileSize}}KB</p>
      </div>
      <div class="pdfjs"></div>
      <button v-if="!openFile" type="button" class="download-btn" @click="getFiles">暂不支持下载</button>
    </div>
</template>

<script>
  import pdf from 'pdfjs-dist'
  import $ from "jquery"
  import "../../assets/js/pdfh5";
  import "../../assets/css/pdfh5.css"
    export default {
        name: "noticeFileInfo",
      data() {
          return{
            fileName: '',
            fileSize: 0,
            fileUrl: '',
            openFile: false
          }
      },
      mounted(){
          this.fileUrl = this.$route.params.url;
          this.fileName = this.$route.params.name;
          this.fileSize = this.$route.params.size;
      },
      methods: {
        getFiles(){
          this.openFile = false;
          var pdfh5 = new Pdfh5('.pdfjs', {
            pdfurl: this.fileUrl
          });

          pdfh5.on("renderPages",function(currentPageDom){
            // console.log(this.currentNum)
            // console.log(pdfh5.currentNum)
          })
        }
      }
    }
</script>

<style scoped>
  .download-btn{
    width: 345px;
    height: 45px;
    background-color: #4852D0;
    border-radius: 2px;
    position: fixed;
    left: 15px;
    bottom: 16px;
    border: none;
    color: #ffffff;
  }
  .download-btn:active{
    background-color: rgba(72, 82, 208, 0.8);
  }
  .file{
    text-align: center;
    background-color: #ffffff;
    padding-top: 36%;
  }
  .file-icon{
    width: 64px;
    height: 64px;
  }
  .file-name{
    font-size: 18px;
    color: #333333;
    margin-top: 18px;
    line-height: 18px;
  }
  .file-size{
    font-size: 14px;
    color: #9f9f9f;
    margin-top: 20px;
    line-height: 14px;
  }
  .pdfjs {
    width: 100%;
    min-height: 300px;
    overflow: hidden;
    background: #fff;
    position: relative;
  } 
</style>
